

#include "TrackPath.h"

namespace ljl{

#if 1
void TRACKPATH::SavePath(ljl::BOOSTPATH* pPATH, string filename)
{
    cout << endl << "Saving keyframe trajectory to " << filename << " ..." << endl;  //"xxx.bin"

    std::ofstream ofs(filename);
    if(!ofs.is_open() ){
	std::cout << "filename open failed!" << endl;
	exit(-1);

    }
	pPATH->mvTrackPaths.push_back(pPATH->mvTrackPath);
	pPATH->mvTrackPaths.push_back(pPATH->mvTrackPath);
    //使用二进制的方式序列化
    if(filename.find(".txt") != filename.npos){
	boost::archive::text_oarchive boost_oa(ofs);
        boost_oa << pPATH;
    }
    else if(filename.find(".bin") != filename.npos){
        boost::archive::binary_oarchive boost_oa(ofs);
        boost_oa << pPATH;
    }
    else{
	cout << "trackpath file neither .bin or .txt" << endl;
	exit(-1);
    }
    cout << "path size is :  "<< pPATH->mvTrackPaths.size()<<endl;
    ofs.close();

    cout << endl << "trajectory saved!" << endl;

}
#endif
//ljl::BOOSTPATH* &pPATH   must use '&', otherwise it is diffrient bettwen in in_function and out_function
void TRACKPATH::LoadPath(ljl::BOOSTPATH* &pPATH, string filename)       
{
    cout << endl << "load keyframe trajectory from " << filename << " ..." << endl;  //"xxx.bin"

    std::ifstream ifs(filename);
    if(!ifs.is_open() ){
	std::cout << "filename open failed!" << endl;
	exit(-1);

    }
 
    if(filename.find(".txt") != filename.npos){
        boost::archive::text_iarchive boost_ia(ifs);
        boost_ia >> pPATH;
    }
    else if(filename.find(".bin") != filename.npos){
        boost::archive::binary_iarchive boost_ia(ifs);
	boost_ia >> pPATH;
    }
    else{
	cout << "load file neither .bin or .txt " << endl;
	exit(-1);
    }
 
    ifs.close();
    cout << endl << "load size is :   " << pPATH->mvTrackPaths.size() << endl;
    cout << endl << "trajectory loaded!" << endl;
}

}
